package com.myapp.ruyixing.http;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

import com.myapp.ruyixing.model.ShopInfo;
import com.myapp.ruyixing.model.ShopInfo.InfoItem;

public class ShopInfoParser extends RYJSONParser {
	@Override
	public Object parse(JSONObject jsonObject) {

		ShopInfo shopInfo = new ShopInfo();
		shopInfo.items = new ArrayList<ShopInfo.InfoItem>();

		ModelParser.parseModel(shopInfo, jsonObject);

		JSONObject data = jsonObject.optJSONObject("data");
		shopInfo.price = data.optString("price", "");
		shopInfo.fuwu = data.optString("fuwu", "");
		shopInfo.shopname = data.optString("shopname", "");
		shopInfo.weisheng = data.optString("weisheng", "");
		shopInfo.score = data.optInt("score", 0);
		shopInfo.picurl = data.optString("picurl", "");

		JSONArray list = data.optJSONArray("items");

		for (int i = 0; list != null && i < list.length(); i++) {
			JSONObject object = list.optJSONObject(i);
			if (object != null) {

				InfoItem item = new InfoItem();
				item.content = object.optString("content", "");
				item.title = object.optString("title", "");
				item.field = object.optString("field", "");
				shopInfo.items.add(item);
			}
		}

		return shopInfo;

	}
}
